<%--
  Created by IntelliJ IDEA.
  tip: lichengming
  Date: 2017/6/14
  Time: 下午4:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/resources.jsp" %>


<html>
<head>
    <title>管理员列表</title>
</head>
<body>
<div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">查询条件</h3>
        </div>
        <div class="panel-body">
            <form class="form-inline">
                <div class="form-group">
                    <%--<label for="searchCode">编码：</label>--%>
                    <input type="text" class="form-control" id="searchCode" name="code" placeholder="编码">
                </div>
                <div class="form-group">
                    <%--<label for="searchTip">提示语：</label>--%>
                    <input type="text" class="form-control" id="searchTip" name="tip" placeholder="提示语">
                </div>
                <div class="form-group">
                    <button type="button" class="btn btn-info btn-search">查询</button>
                    <button type="button" class="btn btn-default btn-reset">清空</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="ems_table_content">
    <div class="panel panel-default">
        <div class="panel-heading">管理员列表</div>
        <div id="table_tools">
            <div class="form-inline" role="form">
                <button type="button" id="tip_add" class="btn btn-outline btn-success">
                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                    添加
                </button>
                <button type="button" id="tip_edit" class="btn btn-outline btn-primary">
                    <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                    修改
                </button>
                <button type="button" id="tip_delete" class="btn btn-outline btn-danger">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                    删除
                </button>
            </div>
        </div>
        <table id="tipTable"
               data-url="/ems/tip/pagination"
               data-show-export="true">
            <thead>
            <tr>
                <th data-field="state" data-checkbox="true"></th>
                <th data-field="code">编码</th>
                <th data-field="tip">提示</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<script>
    function statusFormat(srcValue) {
        if (srcValue == 1) {
            return "<span style='color: #3cb371;font-weight: bold' >正常</span>";
        }else {
            return "<span style='color: red;font-weight: bold'>冻结</span>";
        }
    }

    function search(params) {
        var queryParams = {"query":params};
        $('#tipTable').bootstrapTable('refresh', queryParams);
    }
</script>

<script>

    var dialogOption = {
        width:"500px",
        height:"300px",
        url:"/ems/tip/edit",
        yesFn:function(){
            var result = tipSave();
            if (result) search(getQueryParams());
            return result;
        }
    }

    $(function () {
        $("#tipTable").createTable();

        //添加
        $("#tip_add").on("click",function () {
            dialogOption.data = {};
            dialogOption.title = "提示语新增";
            $("#tip_add_dialog").openDialog(dialogOption);
        })

        //编辑
        $("#tip_edit").on("click",function () {
            var selectRows =  $('#tipTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要编辑的数据");
                return;
            }
            if (selectRows.length > 1) {
                $.errorAlert("暂时不支持多行数据编辑");
                return;
            }

            var rowId =  selectRows[0].id;
            dialogOption.title = "提示语编辑";
            dialogOption.data = {tipId : rowId};
            $("#tip_add_dialog").openDialog(dialogOption);
        })

        //删除
        $("#tip_delete").on("click",function () {
            var selectRows =  $('#tipTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要删除的数据");
                return;
            }

            var tipIdList = "";
            for (var i = 0;i<selectRows.length;i++) {
                tipIdList += selectRows[i].id + ",";
            }
            tipIdList = tipIdList.substring(0,tipIdList.length - 1);

            $.confirmAlert("你确定要删除这些数据吗",function(){
                $.emsAjax({
                    data:{tipIdList:tipIdList},
                    type:"POST",
                    url:"/ems/tip/delete",
                    success:function(resp) {
                        if (resp.status == "000") {
                            $.alert(resp.message);
                            search("#tipTable",getQueryParams());
                        }else {
                            $.errorAlert(resp.message);
                        }
                    }
                });
            });
        });

        //搜索
        $(".btn-search").on("click",function () {
            search(getQueryParams());
        });

        //重置
        $(".btn-reset").on("click",function () {
            $("#queryForm").find("input,select").each(function (index,val) {
                $(val).val("");
            });
        });
    })
</script>
<div id="tip_add_dialog"></div>
</body>
</html>
